#ifndef _COMMANDPARSER_H
#define _COMMANDPARSER_H
#include "global.h"
#include "BinArchive.h"
namespace parser
{
struct Command
{
public:
	/** handle the message. */
	virtual void perform() = 0;
	virtual void HandleMessage(ISysBusObject* msg){perform();}
	virtual UINT32 cmdID() = 0;
};
/**command define*/
#define GROUP_ITEM(	 OP, t,	m )		GROUP_ITEM_##OP(t, m)
#define GROUP_ITEM_MEMBER(t, m)		t m;
#define GROUP_ITEM_SERIAL(t, m)		bin.serialize(m);
#define DefCommand(command) \
struct CMD_##command : public parser::Command {	\
	UINT32 cmdID() {return command;}\
	virtual void perform();\
	virtual void HandleMessage(ISysBusObject* msg){\
	BinDearchive bin(msg->Context(), msg->Length());\
	COMMAND_CONTENT_##command(SERIAL);\
	parser::Command::HandleMessage(msg);}\
	COMMAND_CONTENT_##command(MEMBER);\
};
/**command parser*/
class CommandParser
{
public:
	CommandParser(void);
	~CommandParser(void);
	void paserData(ISysBusObject* msg);
	void registerCommand(Command * cmd);
	Command * findCommand(UINT32 cmdID) const;
 private:
	/** registered commands */
	 std::map<UINT32,Command*> m_commandList;
};
}
#endif//_COMMANDPARSER_H